import request from '@/utils/request'
import upload from '@/utils/upload'

// 登录方法
export function login(dept,phone, password, code, uuid) {
	const data = {
		dept,
		phone,
		password,
		grandType: undefined,
		clientId: 'APP',
		deviceType: 'APP',
		clientSecret: '12345678'
	}
	return request({
		'url': '/auth/logi/oauth/login?code='+code+'&uuid='+uuid,
		headers: {
			isToken: false
		},
		'method': 'post',
		'data': data
	})
}

// 自动登录方法
export function autoLogin(dept,phone, password) {
	const data = {
		dept,
		phone,
		password,
		clientId: 'APP',
		deviceType: 'APP',
		clientSecret: '12345678'
	}
	return request({
		'url': '/auth/logi/oauth/login?grant_type=refresh_token',
		headers: {
			isToken: false
		},
		'method': 'post',
		'data': data
	})
}

// 注册方法
export function register(data) {
	return request({
		url: '/auth/logi/oauth/register',
		headers: {
			isToken: false
		},
		method: 'post',
		data: data
	})
}

// 获取用户详细信息
export function getInfo() {
	return request({
		'url': '/logi/logi/user/getInfo',
		'method': 'get'
	})
}

// 退出方法
export function logout() {
	return request({
		'url': '/auth/oauth/logout',
		'method': 'post'
	})
}

// 获取验证码
export function getCodeImg() {
	return request({
		'url': '/captchaImage',
		headers: {
			isToken: false
		},
		method: 'get',
		timeout: 20000
	})
}

// 获取短信验证码
export function regSendSms(query) {
  return request({
    url: '/auth/oauth/sms/regSms',
    headers: {
      isToken: false
    },
    method: 'get',
    params: query
  })
}

//验证码认证
export function verifyCode(query) {
  return request({
    url: '/auth/logi/oauth/verify',
    headers: {
      isToken: false
    },
    method: 'get',
    params: {
      phone:query.phone,
      verifyCode:query.verifyCode
    }
  })
}

// 手机号修改密码(无需验证码)
export function resetPwd(phone,query) {
  return request({
    url: '/logi/logi/user/resetPwd/'+phone,
    method: 'get',
    params: query
  })
}

// 手机号修改密码->获取短信验证码后
export function phone_resetPwd(data) {
  return request({
    url: '/auth/logi/oauth/resetMainUserPwd',
    headers: {
      isToken: false
    },
    method: 'post',
    data: data
  })
}

// 新增部门扩展信息
export function deptextAdd(data) {
  return request({
    url: '/logi/logi/deptExt',
    method: 'post',
    data: data
  })
}

// 查询部门扩展信息
export function getByDeptIdDetail(deptId) {
  return request({
    url: '/logi/logi/deptExt/getByDeptId/' + deptId,
    method: 'get',
  })
}

// 上传认证部门的相关附件
export function uploadFile(tempFiles) {
    return upload({
		url: '/sys/oss/upload',
		filePath:tempFiles[0].path,
		file:tempFiles[0].file
    })
}

// 更新用户手机号码
export function changeUserPhone(query) {
  return request({
    url: '/logi/logi/user/changeUserPhone',
    method: 'get',
    params: query
  })
}
